<script>
	export default {
		onLaunch: function() {
			console.log('onLaunch')
		},
		onShow: function() {
			console.log('onShow')
		},
		onHide: function() {
			console.log('onHide')
		},
		watch: {
			"$store.state.user"(val, oldval) {
				if (val) {
					//连接websocket
					this.initWebsocket(val)
				} else {
					//关闭websocket
					this.closeWebsocket()
					uni.clearStorageSync()
					uni.navigateTo({
						url: '/pages/login'
					})
				}
			}
		},
		methods: {
			//连接websocket
			initWebsocket(userId) {
				this.$store.dispatch('websocketInit', userId)
			},
			//关闭websocket
			closeWebsocket() {
				this.$store.dispatch('websocketClose')
			},
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	//引入公共样式
	@import '@/static/css/common.css';

	/*每个页面公共css */
	page {
		width: 100%;
		height: 100%;
		overflow: hidden;

		/deep/.uni-date__x-input {
			background-color: #f2f2f2;
			padding-left: 10rpx;
			border-radius: 10rpx;
		}

		/deep/.u-checkbox-group--row {
			flex-wrap: wrap;
		}
	}
</style>